home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DBVGAL17.ARJ / SRC_C.ARJ / VIDLIB4.C < prev    next >
C/C++ Source or Header  |  1992-01-26  |  5KB  |  150 lines

  1. #include <dos.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <conio.h>
  6. #include <mem.h>
  7. #include "vidlib.h"
  8.  
  9. /* video to video copy, 16 colors, planar */
  10. int Vcopy16(unsigned dx, unsigned dy,
  11.             unsigned sx, unsigned sy, unsigned sdx, unsigned sdy)
  12. {
  13.    char *dest;
  14.    char *src;
  15.    unsigned yo;
  16.    int  oldWmode;
  17.  
  18.    /* check parameters */
  19.    if ( (dx+sdx > _screen_width) || (sx+sdx > _screen_width) ||
  20.         (dy+sdy > _memory_length) || (sy+sdy > _memory_length) ||
  21.         ((long)(sdx * sdy) > 0xFFFFL ) )
  22.        return(0);
  23.    if ( vgadebug != NULL ) {
  24.       sprintf(tdbg,"Vc16: dx=%u, dy=%u, sx=%u, sy=%u, sdx=%u, sdy=%u\n",
  25.                    dx, dy, sx, sy, sdx, sdy);
  26.       fputs(tdbg,vgadebug);
  27.    }
  28.  
  29.    oldWmode=What_Wmode();
  30.    Select_Wmode(1);
  31.    dest=(char *)normalize(_screen_start + dy*_screen_width + dx);
  32.    src=(char *)normalize(_screen_start + sy*_screen_width + sx);
  33.    if ( vgadebug != NULL ) {
  34.      sprintf(tdbg,"     : dest=%Fp, src=%Fp, m1=%u, m2=%u\n",
  35.                   dest, src, oldWmode, What_Wmode());
  36.      fputs(tdbg,vgadebug);
  37.    }
  38.    for (yo=0; yo < sdy; yo++) {
  39.           /* must use a byte-at-a-time copy only here! */
  40.           memcpyb(dest, src, sdx);
  41.           dest=(char *)normalize(dest + _screen_width);
  42.           src=(char *)normalize(src + _screen_width);
  43.    }
  44.    Select_Wmode(oldWmode);
  45.    return(1);
  46. }
  47.  
  48. /* Memory to video copy, 16 color, planar memory to planar  video */
  49. int Vdisp16( unsigned dx, unsigned dy,
  50.              char *s, unsigned sw, unsigned sl,
  51.              unsigned sx, unsigned sy, unsigned sdx, unsigned sdy)
  52. {
  53.    char *dest;
  54.    char *src;
  55.    unsigned yo;
  56.  
  57.    /* check parameters */
  58.    if ( ( dx+sdx > _screen_width) || (dy+sdy > _memory_length) ||
  59.         ( sx+sdx > sw) || (sy+sdy > sl) ) {
  60.       printf("Invalid parameters to Vdisp16\n");
  61.       return(0);
  62.    }
  63.    dest=(char *)normalize(_screen_start + dy*_screen_width + dx);
  64.    src=(char *)normalize(s + sy*sw*4 + sx);
  65.  
  66.    if ( vgadebug != NULL ) {
  67.       sprintf(tdbg,"Vd16: dx=%u, dy=%u, s=%Fp, sw=%u, sl=%u, sx=%u\n"
  68.                    "      sy=%u, sdx=%u, sdy=%u\n",
  69.                    dx, dy, s, sw, sl, sx, sy, sdx, sdy);
  70.       fputs(tdbg,vgadebug);
  71.       sprintf(tdbg,"    : dest=%Fp, src=%Fp\nGC[0]=%x, GC[1]=%x, GC[2]=%u"
  72.                    ", GC[3]=%u, GC[5]=%u, GC[8]=%x\n", dest, src,
  73.                    GCread_reg(0), GCread_reg(1), GCread_reg(2), GCread_reg(3),
  74.                    GCread_reg(5), GCread_reg(8));
  75.       fputs(tdbg,vgadebug);
  76.    }
  77.    Select_Wmode(0);
  78.  
  79.    for (yo=0; yo < sdy; yo++) {
  80.        Select_WPlane(WPlane0);
  81.        memcpy(dest,src,sdx);
  82.        src=(char *)normalize(src + sw);
  83.  
  84.        Select_WPlane(WPlane1);
  85.        memcpy(dest,src,sdx);
  86.        src=(char *)normalize(src + sw);
  87.  
  88.        Select_WPlane(WPlane2);
  89.        memcpy(dest,src,sdx);
  90.        src=(char *)normalize(src + sw);
  91.  
  92.        Select_WPlane(WPlane3);
  93.        memcpy(dest,src,sdx);
  94.        dest=(char *)normalize(dest + _screen_width);
  95.        src=(char *)normalize(src + sw);
  96.    }
  97.    Select_WPlane(WPlaneALL);
  98.    return(1);
  99. }
  100.  
  101. /* Video to Memory copy, 16 color, planar video to planar memory */
  102. int Vcapt16( char *d, unsigned dw, unsigned dl,
  103.                           unsigned dx, unsigned dy,
  104.                       unsigned sx, unsigned sy, unsigned sdx, unsigned sdy)
  105. {
  106.    char *dest;
  107.    char *src;
  108.    unsigned yo;
  109.  
  110.    /* check parameters */
  111.    if ( ( sx+sdx > _screen_width) || (sy+sdy > _memory_length) ||
  112.         ( dx+sdx > dw) || (dy+sdy > dl) ) {
  113.       printf("Invalid parameters to Vdisp16\n");
  114.       return(0);
  115.    }
  116.    src=(char *)normalize(_screen_start + sy*_screen_width + sx);
  117.    dest=(char *)normalize(d + dy*dw*4 + dx);
  118.  
  119.    if ( vgadebug != NULL ) {
  120.       sprintf(tdbg,"Vct16: d=%Fp, dw=%u, dl=%u, dx=%u, dy=%u\n"
  121.                    "       sx=%u, sy=%u, sdx=%u, sdy=%u\n",
  122.                    d, dw, dl, dx, dy, sx, sy, sdx, sdy);
  123.       fputs(tdbg,vgadebug);
  124.       sprintf(tdbg,"    : dest=%Fp, src=%Fp\n", dest, src);
  125.       fputs(tdbg,vgadebug);
  126.    }
  127.  
  128.    for (yo=0; yo < sdy; yo++) {
  129.        Select_RPlane(0);
  130.        memcpy(dest, src, sdx);
  131.        dest=(char *)normalize(dest + dw);
  132.  
  133.        Select_RPlane(1);
  134.        memcpy(dest, src, sdx);
  135.        dest=(char *)normalize(dest + dw);
  136.  
  137.        Select_RPlane(2);
  138.        memcpy(dest, src, sdx);
  139.        dest=(char *)normalize(dest + dw);
  140.  
  141.        Select_RPlane(3);
  142.        memcpy(dest, src, sdx);
  143.        src=(char *)normalize(src + _screen_width);
  144.        dest=(char *)normalize(dest + dw);
  145.    }
  146.    return(1);
  147. }
  148.  
  149.  
  150.